define(
    ["PDUtilDir/dataService", "PDUtilDir/grid", "PDUtilDir/searchBlock", "PDUtilDir/util", "PDUtilDir/tool", "PDUtilDir/slidebar", "PDUtilDir/inputSelect", "Date", "DateCN", "css!DateCss"],
    function (DataService, Grid, SearchBlock, Util, Tool, Slidebar, inputSelect) {
        function choiceDriverSupportInit($scope, $compile) {
            return new choiceDriverSupport($scope, $compile);
        };

        function choiceDriverSupport($scope, $compile) {
            this.$scope = $scope;
            this.$compile = $compile;
        };
        choiceDriverSupport.fn = choiceDriverSupport.prototype;

        choiceDriverSupport.fn.init = function (uuid) {
            var _this = this;
            _this.entity = {
                uuid: uuid
            };
            _this.search = {};
        };

        choiceDriverSupport.fn.digest = function () {
            this.$scope.$digest();
        };

        choiceDriverSupport.fn.run = function (uuid) {
            var _this = this;
            _this.init(uuid);

            this.slidebars = Slidebar({
                size: 'lg',
                url: getServer()
                + "/static/app/fleet/cteamOrderInfos/views/driver.html",
                $scope: _this.$scope,
                $compile: _this.$compile,
                afterLoad: function ($Panel) {
                    _this.initialization();
                }
            });
        };
        choiceDriverSupport.fn.initialization = function () {
            this.baseInit();
        };
        /* 查询 start */
        choiceDriverSupport.fn.searchSupport = function () {
            var _this = this;
            return {
                run: function(){
                    _this.grid.reload({
                        queryParam : {
                            model: JSON.stringify(_this.search)
                        }
                    })
                }
            }
        };
        choiceDriverSupport.fn.save = function() {
            DataService.setObject('car.team.search.driver', this.entity);
            this.$scope.agreeSupport.reloadDriverSupport().run();
            this.slidebars.close();
        };
        choiceDriverSupport.fn.baseInit = function () {
            var _this = this;

            SearchBlock.init('DriverSearchBlockId');
            _this.grid = Grid({
                id: "DriverGirdDivId",
                pageSize: 10,
                index: true,
                multi: false,
                pagination: true,
                cache: false,
                onSeletedChanged : function(data) {
                    _this.entity = $.extend(data[0], {
                        uuid: _this.entity.uuid
                    });
                    _this.digest();
                },
                layout: [ {
                    name : "姓名",
                    field : "name",
                    sort : true
                }, {
                    name : "性别",
                    field : "sex"
                }, {
                    name : "年龄",
                    field : "age"
                }, {
                    name : "联系电话",
                    field : "phone"
                }, {
                    name : "身份证",
                    field : "cardId"
                }, {
                    name : "状态",
                    field : "status"
                }],
                toolbar: [ {
                    name : "查询",
                    icon : "fa fa-search",
                    callback : function(event) {
                        _this.searchSupport().run();
                    }
                }],
                data : {
                    type : 'URL',
                    value : getServer() + '/flea/hclv/driver/selectByDeptId.htmls'
                }
            });
        };

        return choiceDriverSupportInit;
    });